using Godot;
using System;

public partial class PlayerParticleEmitter : Node
{

    [Export]
    public PackedScene DamageParticle { get; set; }
    [Export]
    public PackedScene HealingParticle { get; set; }

    // Node references
    private int _pidIterator = 0;
    private Node _particleLayer;
    private Player _player;

    public override void _Ready()
    {
        var map = GetNode<NodeReferenceMap>(Constants.NodeRefMapPath);
        _particleLayer = map.ParticleLayer;
        _player = map.MainPlayer;
    }


    // Export interfaces
    public void CreateDamageParticle()
    {
        var particle = DamageParticle.Instantiate<SelfFreeParticle>();
        AppendParticle(particle, _player.GlobalPosition);
    }

    public void CreateHealingParticle()
    {
        var particle = HealingParticle.Instantiate<SelfFreeParticle>();
        AppendParticle(particle, _player.GlobalPosition);
    }

    
    // Private functions
    private void AppendParticle(SelfFreeParticle particle, Vector2 position)
    {
        particle.ParticleID = ++_pidIterator;
        particle.GlobalPosition = position;
        particle.PlayFinished += Signal_ParticleFinished;
        _particleLayer.AddChild(particle);
        particle.Emitting = true;
    }


    // GODOT Signals
    private void Signal_ParticleFinished(int particleID, int type)
    {

    }
}
